package com.jvm;

import co.paralleluniverse.fibers.Fiber;

public class JVM_31_纤程 {

    /**
     * 使用方式：
     * ------------------------------------------------------------------------------
     * 1、加入依赖
     * <dependency>
     * <groupId>co.paralleluniverse</groupId>
     * <artifactId>quasar-core</artifactId>
     * <version>0.8.0</version>
     * </dependency>
     * -----------------------------------------------------------------------------
     * 2、使用 maven-dependency-plugin 插件，在pom.xml 中的 plugins 中加入如下配置
     * <plugin>
     * <groupId>org.apache.maven.plugins</groupId>
     * <artifactId>maven-compiler-plugin</artifactId>
     * <configuration>
     * <source>9</source>
     * <target>9</target>
     * </configuration>
     * </plugin>
     * -----------------------------------------------------------------------------
     * 3、使用 maven-surefire-plugin 加上 agent 参数
     * <plugin>
     * <groupId>org.apache.maven.plugins</groupId>
     * <artifactId>maven-surefire-plugin</artifactId>
     * <configuration>
     * <!-- Turn off before production -->
     * <argLine>-Dco.paralleluniverse.fibers.verifyInstrumentation=true</argLine>
     * <!-- Enable if using compile-time (AoT) instrumentation -->
     * <!-- argLine>-Dco.paralleluniverse.fibers.disableAgentWarning</argLine -->
     * <argLine>-javaagent:${co.paralleluniverse:quasar-core:jar:jdk8}</argLine>
     * </configuration>
     * </plugin>
     */


    /**
     * 经验证，线程执行完代码需要5秒左右，纤程在执行完在1秒内
     */
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        for (int i = 0; i < 10000; i++) {
//            new Thread(JVM_31_纤程::execute).start();
            new Fiber<Void>(JVM_31_纤程::execute).start();
        }
        System.out.println("耗时：" + (System.currentTimeMillis() - start));

    }

    static void execute() {
        for (int i = 0; i < 100; i++) ;
    }

}
